from flask import current_app
from flask import request, jsonify,render_template
from flask import session

from ihome.models import House, User
from ihome.utils.response_code import RET
from . import api

@api.route('/houses/<int:id>')
def houses(id):

    #获取用户信息


    #获取用户id如果没有登录返回－１
    user_id = -1

    user_id = session.get('user_id')

    #假装用户已经登录，从数据库直接获取用户信息
    # user = User.query.get('7')



    #判空
    if not id:
        return jsonify(errno=RET.PARAMERR, errmsg='参数错误')

    # 获取房间信息
    try:
        house = House.query.get(id)
    except Exception as e:
        current_app.logger.error(e)
        return jsonify(errno=RET.DBERR, errmsg='数据库查询错误')

    house = house.to_full_dict() if house else None
    # user = user.to_dict()



    return jsonify(errno=RET.OK, errmsg='操作成功',data={"house":house,'user_id':user_id})




